import 'package:flutter/material.dart';
import 'package:flutter_roujiaosuo/ui/components/home/navBar.dart';

class CategoryView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    List leftList = [
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
      '热门',
    ];
    double viewportFraction = 1 / 10;
    PageController controller = new PageController(
        initialPage: 0, keepPage: true, viewportFraction: viewportFraction);
    return Scaffold(
      appBar: HomeNavBar(
        // leaddingMaxWidth: 414.0,
        titleSpacing: -50,
        centerTitle: true,
        title: Leadding(),
        gradientStart: Theme.of(context).primaryColor,
        gradientEnd: Theme.of(context).primaryColor,
      ),
      body: LeftPageView(
        data: leftList,
        controller: controller,
      ),
    );
  }
}

class Leadding extends StatelessWidget {
  const Leadding({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 35,
      width: MediaQuery.of(context).size.width - 80,
      decoration: BoxDecoration(
          color: Colors.grey[200],
          borderRadius: BorderRadius.all(Radius.circular(2))),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          Row(
            children: <Widget>[Icon(Icons.search), Text('搜索商品、商家、服务')],
          ),
          Icon(Icons.voice_chat)
        ],
      ),
    );
  }
}

class LeftPageView extends StatelessWidget {
  const LeftPageView({Key key, this.data, this.controller}) : super(key: key);
  final List data;
  final PageController controller;
  @override
  Widget build(BuildContext context) {
    return Container(
      child: PageView.builder(
        scrollDirection: Axis.vertical,
        controller: controller,
        physics: BouncingScrollPhysics(),
        itemCount: 10,
        itemBuilder: (context, index) {
          return this.data.map((item) => LeftItem()).toList()[index];
        },
      ),
    );
  }
}

class LeftItem extends StatelessWidget {
  const LeftItem({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      // color: Colors.red,
      decoration: BoxDecoration(
          backgroundBlendMode: BlendMode.overlay,
          // gradient: SweepGradient(colors: [Colors.green, Colors.blue])),
          // gradient: RadialGradient(colors: [Colors.green, Colors.blue])),
          gradient: LinearGradient(colors: [Colors.green, Colors.blue])),
      child: Text('aaa'),
    );
  }
}
